<link href="admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<{$config.weburl}>/script/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="<{$config.weburl}>/script/jquery.ui.js"></script>
<script type="text/javascript" src="<{$config.weburl}>/script/Validator.js"></script>
<div class="container">
<div>
<input name="act" type="hidden" id="act" value="create">
<table class="table">
    <thead>
        <tr>
            <th class="partition" colspan="99">生成优惠券礼包</th>
        </tr>
    </thead>
    <tbody>
    <tr>
    	<td>会员：</td>
        <td>
        	<textarea name="member_id" id="member_id" placeholder="会员ID，支持逗号分隔的多个"></textarea>
       	</td>
    </tr>
    <tr>
        <td width="100">礼包配置</td>
        <td colspan="3">
            <select name="configId" id="configId">
            	<option value="" data-param="">---请选择---</option>
            	<{foreach item=list from=$configArr }>
            		<option value="<{$list.id}>" data-param='<{$list.config_json}>'><{$list.name}></option>
            	<{/foreach}>
            </select>
            <br />
            <table id="coupons" style="display:none;">
            	
            </table>
        </td>
    </tr>
    </tbody>
</table>
<div class="dialog_button">
    <input id="save" type="button" value="生成">
</div>
<div id="error"><{$error}></div> 
<script>
$(function(){
	$('#configId').bind('change',function(){
		var data = $(this).find('option:selected').attr('data-param');
		if(data.length>0){
			var table_con = "<tr><td>满</td><td>减</td><td>数量(张)</td><td>有效期(天)</td></tr>";
			var dataTemp = JSON.parse(data);
			$.each(dataTemp,function(i,item){
				table_con += "<tr><td>"+item.cpns_if+"</td><td>"+item.cpns_then+"</td><td>"+item.cpns_num+"</td><td>"+item.overtime+"</td></tr>";
			})
			
			$('#coupons').html(table_con).show();
		}else{
			$('#coupons').html("").hide();
		}
	});
	//生成
	$("#save").click(function () {
		var member_id = $('#member_id').val();
		var act = $('#act').val();
		var configId = $('#configId').val();
		$.post('<{$config.weburl}>/admin/module.php?m=micro_shop&s=coupons_package_create.php',{"member_id":member_id,"act":act,"configId":configId},function(res){
			if(res.code!=0){
				alert(res.msg);
			}else{
				if(res.msg!=''){
					alert(res.msg);
				}
			    window.parent.main.document.location.reload();
			    window.parent.DialogManager.close("create_coupons_package");
			}
		},'json');
	    return false;
	});
	
});
</script>
</div>
</div>